//
//  WSMoudleManager.m
//  WisdomStar
//
//  Created by 谭飞 on 2018/11/8.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "WSModuleManager.h"

#import "WSNavController.h"
#import "WSLoginViewController.h"
#import "WSTabBarController.h"
#import "ZhStaffTabBarViewController.h"

@implementation WSModuleManager

// 返回根控制器
+ (UIViewController *)getRootController {
    UIViewController *controller;
    if (User_Token) { // 是否已登录过
        if ([[TFUserDefault valueForKey:@"identity"] boolValue]) { // 是否是教师
            WSTabBarController *tabBarCtrl = [WSTabBarController loadFromStoryboard:@"WSTeacher" identifier:[WSTabBarController className]];
            controller = tabBarCtrl;
        } else {
            ZhStaffTabBarViewController *stuTabBarCtrl = [[ZhStaffTabBarViewController alloc] init];
            controller = stuTabBarCtrl;
        }
    } else {
        WSLoginViewController *loginVc = [WSLoginViewController loadFromStoryboard:@"WSLogin" identifier:[WSLoginViewController className]];
        WSNavController *navCtrl = [[WSNavController alloc] initWithRootViewController:loginVc];
        controller = navCtrl;
    }
    return controller;
}


// 设置根控制器
+ (void)setRootViewController:(__kindof UIViewController *)controller {
    typedef void (^Animation)(void);
    Animation animation = ^{
        BOOL oldState = [UIView areAnimationsEnabled];
        [UIView setAnimationsEnabled:NO];
        KAppWindow.rootViewController = controller;
        [UIView setAnimationsEnabled:oldState];
    };
    [UIView transitionWithView:KAppWindow
                      duration:0.5f
                       options:UIViewAnimationOptionTransitionCrossDissolve
                    animations:animation
                    completion:nil];
}


// 显示登录模块
+ (void)showLoginMoudle {
    WSLoginViewController *loginVc = [WSLoginViewController loadFromStoryboard:@"WSLogin" identifier:[WSLoginViewController className]];
    WSNavController *navCtrl = [[WSNavController alloc] initWithRootViewController:loginVc];
    [self setRootViewController:navCtrl];
}

// 显示首页模块
+ (void)showHomeMoudle {
    if ([[TFUserDefault valueForKey:@"identity"] boolValue]) { // 是否是教师
        WSTabBarController *tabBarCtrl = [WSTabBarController loadFromStoryboard:@"WSTeacher" identifier:[WSTabBarController className]];
        [self setRootViewController:tabBarCtrl];
        
    } else {
        ZhStaffTabBarViewController *stuTabBarCtrl = [[ZhStaffTabBarViewController alloc] init];
        [self setRootViewController:stuTabBarCtrl];
    }
}

@end
